/**
 * File Comment: Ita a GUI
 */
package edu.gatech.oad.project.presentation;
//$codepro.audit.disable
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;

import edu.gatech.oad.project.networking.clientSessions.AdminSessionClient;


/**
 * This class is a panel that allows the user
 * to interact with the GUI to edit a user in
 * the system.
 * 
 * @author Group 17
 * @version 1
 */
public class EditUser extends JPanel {
  
  /**
   * Field driver: holds the Driver connected to the GUI
   */
  private Driver driver;
  
  /**
   * Field textField: username
   */
 private JTextField textField;
 
 /**
  * Field textField_1: password
  */
 private JTextField textField_1;
 
 /**
  * Field name: username field
  */
 private String name;
 
 /**
  * Field pass: password field
  */
 private String pass;
 
 /**
  * Field userType: account type
  */
 private int userType;
 
 /**
  * Field status: account status
  */
 private int status;
 
 /**
  * Field comboBox: options for account type
  */
 public JComboBox comboBox;
 
 /**
  * Field comboBox_1: options for account status
  */
 public JComboBox comboBox_1;
 
 /**
  * Field btnEdit: edit account button
  */
 public JButton btnEdit;
 
 /**
  * Field btnDeleteAccount: delete account button
  */
 public JButton btnDeleteAccount;
 
 /**
  * Field btnBackToHome: back button
  */
 public JButton btnBackToHome;

 /**
  * Constructor.
  * 
  * @param driver the Driver connected to the GUI
  */
 public EditUser(Driver driver) {
   this.driver = driver;
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
  gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);
  
  JLabel lblEditUser = new JLabel("View/Edit User");
  lblEditUser.setFont(new Font("Lucida Grande", Font.PLAIN, 30));
  GridBagConstraints gbc_lblEditUser = new GridBagConstraints();
  gbc_lblEditUser.gridwidth = 5;
  gbc_lblEditUser.insets = new Insets(0, 0, 5, 0);
  gbc_lblEditUser.gridx = 0;
  gbc_lblEditUser.gridy = 0;
  add(lblEditUser, gbc_lblEditUser);
  
  JLabel lblUserName = new JLabel("User Name");
  GridBagConstraints gbc_lblUserName = new GridBagConstraints();
  gbc_lblUserName.anchor = GridBagConstraints.EAST;
  gbc_lblUserName.insets = new Insets(0, 0, 5, 5);
  gbc_lblUserName.gridx = 0;
  gbc_lblUserName.gridy = 2;
  add(lblUserName, gbc_lblUserName);
  
  textField = new JTextField();
  textField.addCaretListener(new CaretListener() {
    public void caretUpdate(CaretEvent e) {
      name = textField.getText();
    }
  });
  GridBagConstraints gbc_textField = new GridBagConstraints();
  gbc_textField.gridwidth = 2;
  gbc_textField.insets = new Insets(0, 0, 5, 5);
  gbc_textField.fill = GridBagConstraints.HORIZONTAL;
  gbc_textField.gridx = 1;
  gbc_textField.gridy = 2;
  add(textField, gbc_textField);
  textField.setColumns(10);
  
  JLabel lblPassword = new JLabel("Password");
  GridBagConstraints gbc_lblPassword = new GridBagConstraints();
  gbc_lblPassword.anchor = GridBagConstraints.EAST;
  gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
  gbc_lblPassword.gridx = 0;
  gbc_lblPassword.gridy = 3;
  add(lblPassword, gbc_lblPassword);
  
  textField_1 = new JTextField();
  textField_1.addCaretListener(new CaretListener() {
    public void caretUpdate(CaretEvent e) {
      pass = textField_1.getText();
    }
  });
  GridBagConstraints gbc_textField_1 = new GridBagConstraints();
  gbc_textField_1.gridwidth = 2;
  gbc_textField_1.insets = new Insets(0, 0, 5, 5);
  gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
  gbc_textField_1.gridx = 1;
  gbc_textField_1.gridy = 3;
  add(textField_1, gbc_textField_1);
  textField_1.setColumns(10);
  
  JLabel lblAccountType = new JLabel("Account Type");
  GridBagConstraints gbc_lblAccountType = new GridBagConstraints();
  gbc_lblAccountType.anchor = GridBagConstraints.EAST;
  gbc_lblAccountType.insets = new Insets(0, 0, 5, 5);
  gbc_lblAccountType.gridx = 0;
  gbc_lblAccountType.gridy = 4;
  add(lblAccountType, gbc_lblAccountType);
  
  String[] userTypes = {"Patient","Nurse","Doctor","System Admin"};
  comboBox = new JComboBox(userTypes);
  comboBox.addActionListener(new ComboBoxListener1(this));
  GridBagConstraints gbc_comboBox = new GridBagConstraints();
  gbc_comboBox.gridwidth = 2;
  gbc_comboBox.insets = new Insets(0, 0, 5, 5);
  gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
  gbc_comboBox.gridx = 1;
  gbc_comboBox.gridy = 4;
  add(comboBox, gbc_comboBox);
  
  JLabel lblAccountStatus = new JLabel("Account Status");
  GridBagConstraints gbc_lblAccountStatus = new GridBagConstraints();
  gbc_lblAccountStatus.anchor = GridBagConstraints.EAST;
  gbc_lblAccountStatus.insets = new Insets(0, 0, 5, 5);
  gbc_lblAccountStatus.gridx = 0;
  gbc_lblAccountStatus.gridy = 5;
  add(lblAccountStatus, gbc_lblAccountStatus);
  
  String[] statuses = {"Active","Suspended"};
  comboBox_1 = new JComboBox();
  comboBox_1.addActionListener(new ComboBoxListener2(this));
  GridBagConstraints gbc_comboBox_1 = new GridBagConstraints();
  gbc_comboBox_1.gridwidth = 2;
  gbc_comboBox_1.insets = new Insets(0, 0, 5, 5);
  gbc_comboBox_1.fill = GridBagConstraints.HORIZONTAL;
  gbc_comboBox_1.gridx = 1;
  gbc_comboBox_1.gridy = 5;
  add(comboBox_1, gbc_comboBox_1);
  
  btnEdit = new JButton("Edit Account");
  btnEdit.addActionListener(new ButtonListener1(this));
  GridBagConstraints gbc_btnEdit = new GridBagConstraints();
  gbc_btnEdit.insets = new Insets(0, 0, 5, 5);
  gbc_btnEdit.gridx = 1;
  gbc_btnEdit.gridy = 7;
  add(btnEdit, gbc_btnEdit);
  
  btnDeleteAccount = new JButton("Delete Account");
  btnDeleteAccount.addActionListener(new ButtonListener2(this));
  GridBagConstraints gbc_btnDeleteAccount = new GridBagConstraints();
  gbc_btnDeleteAccount.insets = new Insets(0, 0, 5, 5);
  gbc_btnDeleteAccount.gridx = 2;
  gbc_btnDeleteAccount.gridy = 7;
  add(btnDeleteAccount, gbc_btnDeleteAccount);
  
  btnBackToHome = new JButton("Back to Home");
  btnBackToHome.addActionListener(new ButtonListener3(this));
  GridBagConstraints gbc_btnBackToHome = new GridBagConstraints();
  gbc_btnBackToHome.insets = new Insets(0, 0, 0, 5);
  gbc_btnBackToHome.gridx = 1;
  gbc_btnBackToHome.gridy = 8;
  add(btnBackToHome, gbc_btnBackToHome);
 } // end constructor method

 /**
  * Get the Driver.
  * 
  * @return the Driver connected to the GUI
  */
 public Driver getDriver()
 {
   return this.driver;
 } // end getDriver method
 
 /**
  * Get the username.
  * 
  * @return the username
  */
 public String getName()
 {
   return this.name;
 } // end getName method
 
 /**
  * Get the password.
  * 
  * @return the password
  */
 public String getPass()
 {
   return this.pass;
 } // end getPass method
 
 /**
  * Set the account type.
  * 
  * @param type the integer representing the new account type.
  */
 public void setUserType(int type)
 {
   this.userType = type;
 } // end setUserType method
 
 /**
  * Set the account status.
  * 
  * @param status the integer representing the new account status.
  */
 public void setStatus(int status)
 {
   this.status = status;
 } // end setStatus method
 
 /**
  * This private inner class implements ActionListener for comboBox.
  * 
  * @author Group 17
  * @version 1
  */
 private class ComboBoxListener1 implements ActionListener
 {
   /**
    * Field eu: the EditUser being used
    */
   private EditUser eu;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param eu the EditUser being used
    */
   private ComboBoxListener1(EditUser eu)
   {
     this.eu = eu;
     this.driver = eu.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     String usertype = (String)((JComboBox)e.getSource()).getSelectedItem();
     if(usertype.equals("Patient"))
     {
       this.eu.setUserType(0);
     }
     else if(usertype.equals("Nurse"))
     {
       this.eu.setUserType(1);
     }
     else if(usertype.equals("Doctor"))
     {
       this.eu.setUserType(2);
     }
     else if(usertype.equals("System Admin"))
     {
       this.eu.setUserType(3);
     }
   } // end actionPerformed method
 } // end ComboBoxListener1 class
 
 /**
  * This private inner class implements ActionListener for comboBox_1.
  * 
  * @author Group 17
  * @version 1
  */
 private class ComboBoxListener2 implements ActionListener
 {
   /**
    * Field eu: the EditUser being used
    */
   private EditUser eu;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param eu the EditUser being used
    */
   private ComboBoxListener2(EditUser eu)
   {
     this.eu = eu;
     this.driver = eu.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     String status = (String)((JComboBox)e.getSource()).getSelectedItem();
     if(status.equals("Active"))
     {
       this.eu.status = 0;
     }
     else if(status.equals("Suspended"))
     {
       this.eu.status = 1;
     }
   } // end actionPerformed method
 } // end ComboBoxListener2 class
 
 /**
  * This private inner class implements ActionListener for btnEdit.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener1 implements ActionListener
 {
   /**
    * Field eu: the EditUser being used
    */
   private EditUser eu;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param eu the EditUser being used
    */
   private ButtonListener1(EditUser eu)
   {
     this.eu = eu;
     this.driver = eu.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     ((AdminSessionClient) this.driver.getSession()).editUser(this.eu.getName(),this.eu.getUserType(),this.eu.getStatus(),this.eu.getPass());
     this.eu.btnEdit.setText("Account Updated");
   } // end actionPerformed method
 } // end ButtonListener1 class
 
 /**
  * This private inner class implements ActionListener for btnDeleteAccount.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener2 implements ActionListener
 {
   /**
    * Field eu: the EditUser being used
    */
   private EditUser eu;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param eu the EditUser being used
    */
   private ButtonListener2(EditUser eu)
   {
     this.eu = eu;
     this.driver = eu.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     ((AdminSessionClient) this.driver.getSession()).deleteAccount(this.eu.getName());
     this.eu.btnDeleteAccount.setText("Account Deleted");
   } // end actionPerformed method
 } // end ButtonListener2 class
 
 /**
  * This private inner class implements ActionListener for btnBackToHome.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener3 implements ActionListener
 {
   /**
    * Field eu: the EditUser being used
    */
   private EditUser eu;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param eu the EditUser being used
    */
   private ButtonListener3(EditUser eu)
   {
     this.eu = eu;
     this.driver = eu.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent connected to the GUI
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new SysAdminHome(this.driver));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener3 class

public int getUserType() {
    // TODO Auto-generated method stub
    return -1;
}

public int getStatus() {
    // TODO Auto-generated method stub
    return -1;
}
} // end EditUser class